# -*- coding: utf-8 -*-

import unittest
import meteo

'''
Модульный тест для проверки правильности работы
программы для задачи с известным решением
'''
class MeteoTest(unittest.TestCase):

    def setUp(self):
        self.tables = meteo.loadTablesFromDir('tables')

    def tearDown(self):
        pass

    def debugAnswer(self, resDist, resDir):
        print resDist
        print resDir
        print
    
    def checkAnswer(self, expDist, expDir, resDist, resDir):
        for x, y in zip(expDist, resDist):
            assert (x - y) < 20
            
        for x, y in zip(expDir, resDir):
            assert (x - y) < 1

    def testMeteo1(self):
        bull = '1112-19175-0197-52058-02-583802-04-593802-08-593802-12-593802-16-603702-20-613703-24-623704'
        Tz = 5
        h_op = 214
        alpha = 9
        dV0 = -2.9
        dist = (4000, 6000, 8000)
        Z = 'third'
        expDist = [179, 255, 332]
        expDir = [-4, -7, -14]
        resDist, resDir = meteo.computeAll(self.tables, bull, Tz, h_op, Z, alpha, dV0, dist)
        
        self.debugAnswer(resDist, resDir)
        self.checkAnswer(expDist, expDir, resDist, resDir)
        
        
    def testMeteo2(self):
        bull = '1112-02044-0166-01877-02-773606-04-783607-08-783607-12-793507-16-793507-20-803508'
        Tz = -11
        h_op = 66
        alpha = 1
        dV0 = -0.3
        dist = (4000, 6000, 8000)
        Z = 'third'
        expDist = [180, 300, 404]
        expDir = [-5, -9, -16]
        resDist, resDir = meteo.computeAll(self.tables,bull, Tz, h_op, Z, alpha, dV0, dist)
        
        self.debugAnswer(resDist, resDir)        
        self.checkAnswer(expDist, expDir, resDist, resDir)
        
    def testMeteo3(self):
        bull = '1110-03002-0238-00551-02-511009-04-511010-08-511010-12-521110-16-521110-20-531210-24-531210'
        Tz = 14
        h_op = 215
        alpha = 17
        dV0 = -1.2
        dist = (6000, 8000, 10000)
        Z = 'reduced'
        expDist = [190, 301, 445]
        expDir = [-10, -13, -15]
        resDist, resDir = meteo.computeAll(self.tables, bull, Tz, h_op, Z, alpha, dV0, dist)
        
        self.debugAnswer(resDist, resDir)        
        self.checkAnswer(expDist, expDir, resDist, resDir)


if __name__ == "__main__":
    unittest.main()